﻿using System;
using System.Collections.ObjectModel;
using Moq;
using Prompts.ReportCatalog.ViewModels;
using Prompts.ReportCatalog.ViewModels.Implementation;

namespace Test.Prompts.Infrastructure.Fakes
{
    public class FakeReportCatalogViewModelService
    {
        private readonly Mock<IReportCatalogViewModelService> _mock;
        private Action<ObservableCollection<ICatalogItemViewModel>> _callback;

        public FakeReportCatalogViewModelService()
        {
            _mock = new Mock<IReportCatalogViewModelService>();

            _callback = null;
            var setup = _mock.Setup(
                m => m.GetReportCatalog(
                    It.IsAny<Action<ObservableCollection<ICatalogItemViewModel>>>()));

            setup.Callback<Action<ObservableCollection<ICatalogItemViewModel>>>(c =>
            {
                _callback = c;
            });
        }

        public void ExecuteGetReportCatalogCallback(ObservableCollection<ICatalogItemViewModel> catalogItems)
        {
            _callback(catalogItems);
        }

        public IReportCatalogViewModelService Object
        {
            get { return _mock.Object; }
        }

        public void RaiseErrorGettingReports(string errorMessage)
        {
            _mock.Raise(m => m.ErrorGettingReports += null, new ErrorGettingReportsArgs(errorMessage));
        }
    }
}
